import Log from "../utils";

export default {

  namespace: 'global',

  state: {
    locaPath: undefined,
  },

  subscriptions: {
    setup({dispatch, history}) {  // eslint-disable-line

      history.listen(location => {
        // location.pathname
        const len = location.pathname.length;
        const payload = location.pathname.slice(1, len).split('/');
        dispatch({
          type: 'ruteChange',
          payload,
        });
      });
    },
  },

  effects: {
    * fetch({payload}, {call, put}) {  // eslint-disable-line
      yield put({type: 'save'});
    },
  },

  reducers: {
    save(state, action) {
      return {...state, ...action.payload};
    },

    ruteChange(state, action) {
      return {...state, locaPath: action.payload};
    },
  },

};
